package com.atguigu.gmall.controller;

import com.atguigu.gmall.client.ActivityFeignClient;
import com.atguigu.gmall.common.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
/**
 * 商品秒杀控制器
 */
@Controller
@SuppressWarnings("all")
public class SeckillController {

    @Autowired
    private ActivityFeignClient activityFeignClient;

    /**
     * 渲染秒杀商品列表页面
     * @param model 将页面资源放入共享域
     * @return
     */
    @GetMapping("/seckill.html")
    public String seckillIndexHtml(Model model){
        //远程调用秒杀微服务获取秒杀商品列表
        Result result = activityFeignClient.getSeckillGoodsList();
        model.addAttribute("list", result.getData());
        return "/seckill/index";
    }

    /**
     * 渲染秒杀商品详情页面
     * @param model
     * @param skuId
     * @return
     */
    @GetMapping("/seckill/{skuId}.html")
    public String seckillGoodsHtml(Model model,@PathVariable("skuId") Long skuId){
        Result result = activityFeignClient.getSeckillGoods(skuId);
        model.addAttribute("item",result.getData());
        return "/seckill/item";
    }

    /**
     * 渲染抢购页面(排队页面)
     * @param model 共享域
     * @param skuId 商品id
     * @param skuIdStr 抢购码
     * @return
     */
    @GetMapping("/seckill/queue.html")
    public String seckillQueueHtml(Model model, @RequestParam("skuId") Long skuId,@RequestParam("skuIdSrt") String skuIdStr){
        model.addAttribute("skuId", skuId);
        model.addAttribute("skuIdStr", skuIdStr);
        return "/seckill/queue";
    }
}